package com.syz.mall.controller;

import com.syz.mall.pojo.Order;
import com.syz.mall.pojo.query.OrderQuery;
import com.syz.mall.pojo.vo.OrderEchartsVO;
import com.syz.mall.service.ICategoryService;
import com.syz.mall.service.IOrderService;
import com.syz.mall.util.LayUITableResult;
import com.syz.mall.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @Autowired
    private ICategoryService categoryService;
    @RequestMapping("/getOrderListPage")
    public String getOrderListPage() {
        return "/OrderManage/order_list";
    }

    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(OrderQuery orderQuery) {
        //System.out.println("OrderController.selectByPage");
        //System.err.println(orderQuery);
        return orderService.selectByPage(orderQuery);
    }


    @RequestMapping("/deleteById")
    @ResponseBody
    public Result deleteById(Long id) {
        boolean isSuccess = orderService.deleteById(id);
        return isSuccess ? Result.ok("删除成功") : Result.error("删除失败");
    }



    @RequestMapping("/update")
    @ResponseBody
    public Result update(Order order){
        boolean isSuccess = orderService.update(order);
        return isSuccess ? Result.ok("更新成功") : Result.error("更新失败");
    }

    @RequestMapping("/queryEchartsData")
    @ResponseBody
    public List<OrderEchartsVO> queryEchartsData(){
        return orderService.queryEchartsData();
    }

    @RequestMapping("getEchartsPage")
    public String getEchartsPage(){
        return "/echarts";
    }
}
